package com.xhj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhj.client.CourseClient;
import com.xhj.client.UcenterClient;
import com.xhj.entity.Order;
import com.xhj.mapper.OrderMapper;
import com.xhj.service.OrderService;
import com.xhj.util.OrderNoUtil;
import com.xhj.vo.CourseInfoForm;
import com.xhj.vo.MemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 订单(TOrder)表服务实现类
 *
 * @author makejava
 * @since 2021-03-11 11:34:15
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements OrderService {

    @Autowired
    private CourseClient courseClient;

    @Autowired
    private UcenterClient ucenterClient;

    @Override
    public String saveOrder(String courseId, String memberId) {
        // 远程调用获取CourseInfo 和 member
        CourseInfoForm courseInfoForm = courseClient.getCourseInfoVoById(courseId);
        MemberVo memberVo = ucenterClient.getMemberInfoById(memberId);
        Order order = new Order();
        order
                .setOrderNo(OrderNoUtil.getOrderNo())
                .setCourseId(courseId)
                .setCourseTitle(courseInfoForm.getTitle())
                .setCourseCover(courseInfoForm.getCover())
                .setTeacherName("test")
                .setMemberId(memberId)
                .setNickname(memberVo.getNickname())
                .setMobile(memberVo.getMobile())
                .setTotalFee(courseInfoForm.getPrice())
                .setStatus(0)
                .setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}